Socket
Socket
Sign inDemoInstall

sirv

Package Overview
Dependencies
Maintainers
1
Versions
47
Alerts
File Explorer

Advanced tools

Socket logo

Install Socket

Detect and block malicious and high-risk dependencies

Install

sirv

The optimized & lightweight middleware for serving requests to static assets


Version published
Weekly downloads
7M
decreased by-0.51%
Maintainers
1
Weekly downloads
 
Created

What is sirv?

The sirv npm package is a simple, high-performance, single-purpose HTTP server for serving static files. It is designed to be fast and efficient, making it ideal for serving the static assets of web applications.

What are sirv's main functionalities?

Serving static files

This code sample demonstrates how to use sirv with Polka (a lightweight web server) to serve static files from the 'public' directory.

const sirv = require('sirv');
const polka = require('polka');

const server = polka();

server.use(sirv('public'));

server.listen(3000, err => {
  if (err) throw err;
  console.log('> Running on localhost:3000');
});

Customizing options

This code sample shows how to customize sirv with options such as cache control headers and enabling single-page application (SPA) mode.

const sirv = require('sirv');

const options = {
  maxAge: 31536000, // 1 year in seconds
  immutable: true,
  etag: true,
  single: true
};

const serve = sirv('public', options);

Using with middleware

This code sample illustrates how to use sirv as middleware in an Express application to serve static files with development options enabled.

const sirv = require('sirv');
const express = require('express');

const app = express();

app.use(sirv('public', { dev: true }));

app.listen(3000, () => console.log('Server running on port 3000'));

Other packages similar to sirv

FAQs

Package last updated on 20 Dec 2023

Did you know?

Socket

Socket for GitHub automatically highlights issues in each pull request and monitors the health of all your open source dependencies. Discover the contents of your packages and block harmful activity before you install or update your dependencies.

Install

Related posts

SocketSocket SOC 2 Logo

Product

  • Package Alerts
  • Integrations
  • Docs
  • Pricing
  • FAQ
  • Roadmap
  • Changelog

Packages

npm

Stay in touch

Get open source security insights delivered straight into your inbox.


  • Terms
  • Privacy
  • Security

Made with ⚡️ by Socket Inc